package cn.tedu.csmall.passport.web;

import cn.tedu.csmall.passport.ex.ServiceException;
import lombok.Data;

/**
 * ClassName: JsonResult
 * Package: cn.tedu.csmall.passport.web
 * Description 响应结果类
 *
 * @version 0.0.1
 * @Author: 大傻
 * @Create:2022/12/8
 */
@Data
public class JsonResult {
    /**
     * 业务状态码
     */
    private Integer state;
    /**
     * 操作失败时提示消息
     */
    private String message;
    /**
     * 操作成功时候响应数据
     */
    private Object data;
    public static JsonResult ok(){
        return ok(null);
    }

    public static JsonResult ok(Object data){
        JsonResult jsonResult = new JsonResult();
        jsonResult.state=ServiceCode.OK.getValue();
        jsonResult.data=data;
        return jsonResult;
    }
    public static JsonResult fail(ServiceException e){
        return fail(e.getServiceCode(),e.getMessage());
    }

    public static JsonResult fail(ServiceCode serviceCode,String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.state=serviceCode.getValue();
        jsonResult.message=message;
        return jsonResult;

    }

}
